package com.example.redisjson.dto;

import com.redis.om.spring.annotations.Bloom;
import com.redis.om.spring.annotations.Indexed;
import lombok.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.annotation.Reference;
import org.springframework.data.redis.core.RedisHash;

import java.util.Date;

@Data
@RequiredArgsConstructor(staticName = "of")
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor
@RedisHash
public class User {

  @NonNull
  @Indexed
  @Bloom(name = "bf_user_email", capacity = 100000, errorRate = 0.001)
  String email;

  @Id
  private String id;

  @Indexed
  @NonNull
  private String firstName;

  @Indexed
  private String middleName;

  @Indexed
  @NonNull
  private String lastName;

  // audit fields

  @CreatedDate
  private Date createdDate;

  @LastModifiedDate
  private Date lastModifiedDate;
}

// @RedisHash 注解基于 @Documented 注解，并在其基础上添加了存储 Redis 键值对的能力。
// RedisJson 的数据传输实体使用 @RedisHash 注解，和 RedisSearch 的注解 @Document 类似。但两者有不同的作用，不能搞混淆了